package com.party.web.biz.subject;

import com.party.common.utils.StringUtils;
import com.party.core.model.subject.Subject;
import com.party.core.service.crowdfund.IProjectService;
import com.party.core.service.subject.ISubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;

/**
 * 专题
 *
 * @author yifeng
 * @date 2018/9/5 0005
 * @time 下午 18:33
 */
@Service
public class SubjectBizService {
    @Autowired
    private IProjectService projectService;
    @Autowired
    private ISubjectService subjectService;

    public String getReturnUrl(String memberId) {
        if (StringUtils.isNotEmpty(memberId)) {
            List<String> partnerIds = projectService.getPartnerIdByAuthorId(memberId);
            if (partnerIds.size() > 0) {
                List<Subject> subjectIds = subjectService.batchByMember(new HashSet<>(partnerIds), null);
                if (subjectIds.size() == 1) {
                    return "subject/subject_detail.html?id=" + subjectIds.get(0).getId() + "&r=" + System.currentTimeMillis();
                }
            }
        }
        return "subject/subject_list.html?r=" + System.currentTimeMillis();
    }
}
